package com.dsx.haha.servicempl;

import com.dsx.haha.mapper.TenantMapper;
import com.dsx.haha.mapper.TenantUserMapper;
import com.dsx.haha.mapper.UserMapper;
import com.dsx.haha.model.entity.TenantUser;
import com.dsx.haha.model.entity.User;
import com.dsx.haha.service.TenantUserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * @author dsx
 * @date 2021/3/14 15:54
 * @since JDK1.8
 */
@Service
public class TenantUserServiceImpl implements TenantUserService {
    @Autowired
    TenantUserMapper tenantUserMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public int addTenantUser(TenantUser tenantUser) {
        tenantUserMapper.addTenantUser(tenantUser);
        return 1;
    }

    @Override
    public int checkUser(String userId,String tenantId) {
        User user = userMapper.getUserById(userId);
        int i = tenantUserMapper.checkUser(userId, tenantId);
        if (i==0){
            TenantUser tenantUser = new TenantUser();
            tenantUser.setUserId(user.getId());
            tenantUser.setTenantId(tenantId);
            tenantUser.setId("3");
            tenantUser.setCreateTime(new Date());
            tenantUserMapper.addTenantUser(tenantUser);
            return -1;//表示租户中没有这个用户,可以邀请
        }
        return 1;//表示租户中已经存在这个用户，不能邀请
    }
}
